package com.terrace.web.tagext.easyui.support;

import com.terrace.web.tagext.easyui.utils.EasyUIUtils;
import com.terrace.web.tagext.easyui.provider.DataOptionsProvider;

/**
 * 验证框标签
 * @author jiangyg
 *
 */
public abstract class ValidateboxTagSupport extends BaseTagSupport implements DataOptionsProvider {
	
	private static final long serialVersionUID = 5931769040183621755L;

	/**
	 * 定义是否字段应被输入
	 */
	protected boolean required = false;
	
	/**
	 * 定义字段的验证类型，比如 email、url，等等。可能的值：
	 * 				1、验证类型字符串，应用单个验证规则。
	 * 				2、验证类型数组，应用多个验证规则。单个字段上的多个验证规则自版本 1.3.2 起可用。
	 */
	protected String validType;
	
	/**
	 * 延迟验证最后的输入值
	 */
	protected int delay = 200;
	
	/**
	 * 当文本框为空时出现的提示文本
	 */
	protected String missingMessage;
	
	/**
	 * 当文本框的内容无效时出现的提示文本
	 */
	protected String invalidMessage;
	
	/**
	 * 定义当文本框的内容无效时提示消息的位置。可能的值：'left'、'right'
	 */
	protected String tipPosition = "right";
	
	/**
	 * 在 X 方向的提示偏移。该属性自版本 1.3.3 起可用
	 */
	protected int deltaX = 0;
	
	/**
	 * 当设置为 true 时，则禁用验证。该属性自版本 1.3.4 起可用
	 */
	protected boolean novalidate = false;
	
	@Override
	public String assembleBaseDataOptions() {
		StringBuffer sb = new StringBuffer();
		EasyUIUtils.appendDatsOption(sb, "required", required);
		EasyUIUtils.appendDatsOption(sb, "validType", validType);
		EasyUIUtils.appendDatsOption(sb, "delay", delay);
		EasyUIUtils.appendDatsOption(sb, "missingMessage", missingMessage);
		EasyUIUtils.appendDatsOption(sb, "invalidMessage", invalidMessage);
		EasyUIUtils.appendDatsOption(sb, "tipPosition", tipPosition);
		EasyUIUtils.appendDatsOption(sb, "deltaX", deltaX);
		EasyUIUtils.appendDatsOption(sb, "novalidate", novalidate);
		return EasyUIUtils.substringLastComma(sb).toString();
	}
	
	public boolean isRequired() {
		return required;
	}

	public void setRequired(boolean required) {
		this.required = required;
	}

	public String getValidType() {
		return validType;
	}

	public void setValidType(String validType) {
		this.validType = validType;
	}

	public int getDelay() {
		return delay;
	}

	public void setDelay(int delay) {
		this.delay = delay;
	}

	public String getMissingMessage() {
		return missingMessage;
	}

	public void setMissingMessage(String missingMessage) {
		this.missingMessage = missingMessage;
	}

	public String getInvalidMessage() {
		return invalidMessage;
	}

	public void setInvalidMessage(String invalidMessage) {
		this.invalidMessage = invalidMessage;
	}

	public String getTipPosition() {
		return tipPosition;
	}

	public void setTipPosition(String tipPosition) {
		this.tipPosition = tipPosition;
	}

	public int getDeltaX() {
		return deltaX;
	}

	public void setDeltaX(int deltaX) {
		this.deltaX = deltaX;
	}

	public boolean isNovalidate() {
		return novalidate;
	}

	public void setNovalidate(boolean novalidate) {
		this.novalidate = novalidate;
	}

}
